import os, sys

parent_path = os.path.abspath(os.path.join(__file__, *(['..'] * 4)))
sys.path.insert(0, parent_path)

import traceback
import numpy as np
import socket, json, cv2
from typing import *
from core.task.modules.processors.base_processor import BaseProcessor

cls_map={
    0:"背景",
    1:"屋顶",
}

class CustomProcessor(BaseProcessor):
    """将数据通过http回传到接口
    """
    def __init__(self, keys) -> None:
        self.keys = keys
    def __call__(self, data:Dict) -> Dict:
        seg_result = data[self.keys["rooftop"]]
        points = seg_result["points"]
        objects = []
        for img_points_ in points:
            img_objects= []
            for cls_id, cls_points in enumerate(img_points_):
                object_ = {
                    "points":cls_points,
                    "cls_id":int(cls_id),
                    "cls_name": cls_map[cls_id],
                }
                img_objects.append(object_)
            objects.append(img_objects)

        data[self.keys["out"]] = objects
        return data

    def close(self):
        self.status = 0
